﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace dotsoftRAID_Controller
{
    public static class Configuration
    {
        public static List<ConfigurationItem> Load()
        {
            Logging.EnterMethod();

            List<ConfigurationItem> result = new List<ConfigurationItem>();

            XmlDocument doc = new XmlDocument();
            doc.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "raid.xml"));

            foreach (XmlNode raid in doc.SelectNodes("config/raid"))
            {
                ConfigurationItem item = new ConfigurationItem();

                switch (raid.Attributes["type"].Value)
                {
                    case "1":
                        item.Type = ConfigurationItem.RAID_TYPE.RAID1;
                        break;
                    case "5":
                        item.Type = ConfigurationItem.RAID_TYPE.RAID5;
                        break;
                    case "10":
                        item.Type = ConfigurationItem.RAID_TYPE.RAID10;
                        break;
                }

                item.dev0 = raid.Attributes["dev0"].Value;
                item.dev1 = raid.Attributes["dev1"].Value;

                result.Add(item);
            }

            Logging.ExitMethod();

            return result;
        }
    }
}
